// pages/myEvaluation/myEvaluation.js
const { httpPost, httpGet } = require('../../common/js/http')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab: [
      {name: "待评测",selected: true},
      {name: "已测",selected: false}
    ],
    isSelect: 0,
    completed: false //false待测评 true已测
  },
  onShow: function () {
    this.getList()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.getList()
  },
  getList(){
    let examStatus = 0
    if(this.data.completed){
      examStatus = 2
    }else{
      examStatus = '0'
    }
    httpGet({
      url: "/app/orderExam/admin/getOrderExamList",
      data: {examStatus},
      isLoding: true,
      lodingMsg: '加载中...'
    }).then(res =>{
      console.log(res)
      if(res.errorCode == 0){
        this.setData({
          examList: res.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },
  changeTab(e){
    let i = e.target.dataset.index
    if(i == this.data.isSelect){
      return
    }
    // let newTab = this.data.tab
    // newTab.forEach((item,index) => {
    //   item.selected = false
    //   if(index === i){
    //     item.selected = true
    //   }
    // })
    this.setData({
      isSelect : i,
      completed : i == 1 //1代表已测
    })
    this.getList()
  },
  topage(e){
    
    if(e.currentTarget.dataset.orderexamstatus == 0 || e.currentTarget.dataset.orderexamstatus == 1){
      //还未开始测评或已经开始测评，但是没有测完
      wx.navigateTo({
        url: '../examRule/examRule?orderExamId=' + e.currentTarget.dataset.examid + '&examName='+e.currentTarget.dataset.examname,
      })
    }else if(e.currentTarget.dataset.orderexamstatus == 2){
      //已测评
      if(e.currentTarget.dataset.examtype == 1){
        //全项测评 职业优势
        wx.navigateTo({
          url: '../../report/zyysl/zyysl?orderExamId=' + e.currentTarget.dataset.examid
        })
        return
      }else if(e.currentTarget.dataset.examtype == 0){
        //单项测评 
        wx.navigateTo({
          url: '../../report/zydj/zydj?orderExamId=' + e.currentTarget.dataset.examid
        })
        return
      }
      wx.navigateTo({
        // url: '../examRule/examRule?orderExamId=' + e.currentTarget.dataset.examid,
        url: '../../report/zydj/zydj?orderExamId=' + e.currentTarget.dataset.examid
      })
    }
    // else{
    //   //已经开始测评，但是没有测完
    //   wx.navigateTo({
    //     url: '../exam/exam?orderExamId=' + e.currentTarget.dataset.examid,
    //   })
    // }
  }
})